// nsq_producer/nsq_producer.go
package main

import (
	"bufio"
	"fmt"
	"github.com/nsqio/go-nsq"
	"os"
	"strings"
	nsqUtils "utilsx/tools/nsq"
)

var nsqAddress2 = "192.168.20.9:4150"

func main() {
	p := nsqUtils.NewPublisher(nsqAddress2)
	p.InitProducer(nsq.NewConfig())
	reader := bufio.NewReader(os.Stdin) // 从标准输入读取
	for {
		data, err := reader.ReadString('\n')
		if err != nil {
			fmt.Printf("read string from stdin failed, err:%v\n", err)
			continue
		}
		data = strings.TrimSpace(data)
		if strings.ToUpper(data) == "Q" { // 输入Q退出
			break
		}

		err = p.Publish("email", []byte(data))
		if err != nil {
			continue
		}

	}
}
